{% extends 'base.html' %}
{% block content %}
    <div class="container" style="margin-top: 50px;">
        <h1 class="text-center">{{ post.title }}</h1>

        <p>{{ post.content }}</p>
        <h4>Comments</h4>
        <ul class="list-group">
            {% for comment in comments %}
                <li class="list-group-item">
                    {% if comment.author %}
                        <h6>{{ comment.author }}</h6>
                        <p>{{ comment.content }}</p>
                    {% else %}
                        <h6>Anonymous User</h6>
                        <p>{{ comment.content|safe }}</p>
                    {% endif %}
                </li>
            {% endfor %}
        </ul>
        <form id="comment-form" method="POST" action="/add-comment" class="mt-5">
            {% csrf_token %}
            <input type="hidden" name="post-id" value='{{ post.id }}'>
            <div class="form-group">
                <textarea class="form-control" name="comment-textarea" id="comment-textarea" rows="3"></textarea>
                <button id="submit-button" class="btn btn-primary mt-3" type="button">Add Comment</button>
            </div>
        </form>
    </div>
{% endblock %}

{% block extra_script %}
<script>
    document.getElementById('submit-button').addEventListener('click', function() {
        document.getElementById('comment-form').submit();
    });
</script>
{% endblock %}